package com.example.demo_2.dao;

import com.example.demo_2.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

//添加Mapper注解，让UserDao接口，成为Mybatis映射器接口
@Mapper
public interface UserDao {


        @Results(id = "userMap",value = {
            @Result(property = "username",column = "username"),
            @Result(property = "sex",column = "sex"),
            @Result(property = "password",column = "password")
    })
    @Select("select * from student where username = #{username} and password = #{password}")
    User getUserByName(@Param("username") String name, @Param("password") String password);

    @Select("select count(1) from student where username = #{username}")
    int findUserByName(User user);

    @Insert("insert into student(username,password,sex) values (#{username},#{password},#{sex})")
    int creatUser(User user);

    @Delete("delete from student where username=#{username}")
    int deleteUser(User user);

    @Update("update student set username=#{username}, sex=#{sex}, password=#{password} where id=#{id}")
    int updateUser(User user);

//    @Insert("insert into student(name, sex, age) values (#{name}, #{sex}, #{age})")
//    int create(User user);
//
//    // 查询操作
//    @Select("select * from student where name=#{name}")
//    List<User> getByName(String name);
//
//    // 删除操作
//    @Delete("delete from student where name=#{name}")
//    int deleteByName(String name);
//
//    // 更新操作
//    @Update("update student set name=#{name}, sex=#{sex}, age=#{age} where id=#{id}")
//    int updateByName(User user);
}




